<template>
  <editor :formData="student" :formInfoMaps="studentInfoMaps" :rules="rules" v-on:submit="submit"></editor>
</template>

<style>
  .text-right {
    margin-top: 12px;
    text-align: right;
  }

</style>

<script>
  import List from './common/list';
  import {studentInfoMaps, rules} from '../assets/data/student';
  import Editor from './common/editor';

  export default {
    data() {
      return {
          studentId: 0,
          studentInfoMaps: {},
          student: {},
          rules: {}
      }
    },
    mounted() {
      this.studentId = this.$route.query.id;
      this.initStudentData();
    },
    methods: {
      initStudentData() {
        this.studentInfoMaps = studentInfoMaps;
        this.rules = rules;
        this.student = Object.keys(studentInfoMaps).reduce((obj, key) => {
          obj[key] = studentInfoMaps[key].default;
          return obj;
        }, {});
      },
      submit(ev) {
        ajax({
          url: '/student',
          data: this.student,
          method: 'POST'
        }).then(res => {
          this.$message({
            message: '操作成功',
            type: 'success'
          });
          //this.$router.back();
        }).catch(err => {
          this.$message({
            message: '操作失败',
            type: 'error'
          });
        })
      }
    },
    components: {
      'editor': Editor
    }
  }
</script>